from typing import List


class Solution:
    def findBuildings(self, heights: List[int]) -> List[int]:
        ans = []
        last = 0
        for i in range(len(heights) - 1, -1, -1):
            if heights[i] > last:
                ans.append(i)
                last = heights[i]
        ans.reverse()
        return ans


if __name__ == "__main__":
    print(Solution().findBuildings([4, 2, 3, 1]))  # [0,2,3]
    print(Solution().findBuildings([4, 3, 2, 1]))  # [0,1,2,3]
    print(Solution().findBuildings([1, 3, 2, 4]))  # [3]
    print(Solution().findBuildings([2, 2, 2, 2]))  # [3]
